﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sinacor.Servico.Bovespa.Alocacao.Service.ServiceImplementation.Translator.BusinessEntityToDataContract
{
    public class ErroAlocacaoComitente
    {
        public List<DataContract.Response.ErroAlocacaoComitenteResponse> ToErroAlocacaoComitenteResponse(List<BusinessEntity.ErroAlocacaoComitente> from)
        {
            List<DataContract.Response.ErroAlocacaoComitenteResponse> to = null;

            if (from != null)
            {
                to = new List<DataContract.Response.ErroAlocacaoComitenteResponse>();

                foreach (BusinessEntity.ErroAlocacaoComitente item in from)
                {
                    to.Add(ToErroAlocacaoComitenteResponse(item));
                }
            }

            return to;
        }

        public DataContract.Response.ErroAlocacaoComitenteResponse ToErroAlocacaoComitenteResponse(BusinessEntity.ErroAlocacaoComitente from)
        {
            DataContract.Response.ErroAlocacaoComitenteResponse to = null;

            if (from != null)
            {
                to = new DataContract.Response.ErroAlocacaoComitenteResponse();

                to.ApelidoCliente = from.ApelidoCliente;
                to.CodigoNegociacao = from.CodigoNegociacao;
                to.DataPregao = from.DataPregao;
                if (from.NaturezaOperacao.HasValue)
                {
                    switch (from.NaturezaOperacao.Value)
                    { 
                        case Sinacor.Servico.Bovespa.Alocacao.BusinessEntity.Enum.NaturezaOperacao.Compra:
                            to.NaturezaOperacao = Sinacor.Servico.Bovespa.Alocacao.Service.DataContract.Enum.NaturezaOperacao.Compra;
                            break;
                        case Sinacor.Servico.Bovespa.Alocacao.BusinessEntity.Enum.NaturezaOperacao.CompraVenda:
                            to.NaturezaOperacao = Sinacor.Servico.Bovespa.Alocacao.Service.DataContract.Enum.NaturezaOperacao.CompraVenda;
                            break;
                        case Sinacor.Servico.Bovespa.Alocacao.BusinessEntity.Enum.NaturezaOperacao.Venda:
                            to.NaturezaOperacao = Sinacor.Servico.Bovespa.Alocacao.Service.DataContract.Enum.NaturezaOperacao.Venda;
                            break;
                    }
                }
                to.NumeroNegocio = from.NumeroNegocio;
                to.Erro1 = ToErroAlocacao(from.Erro1);
                to.Erro2 = ToErroAlocacao(from.Erro2);
                to.Erro3 = ToErroAlocacao(from.Erro3);
            }

            return to;
        }

        public DataContract.ErroAlocacao ToErroAlocacao(BusinessEntity.ErroAlocacao from)
        {
            DataContract.ErroAlocacao to = null;

            if (from != null)
            {
                to = new DataContract.ErroAlocacao();

                to.CodigoErro = from.CodigoErro;
                to.Descricao = from.Descricao;
                to.NumeroMensagem = from.NumeroMensagem;
                to.Operador = from.Operador;
                to.Tag = from.Tag;
            }

            return to;
        }
    }
}
